﻿//	Copyright (c) 2012 Jonathan Loe
//
//	MIT license (http://en.wikipedia.org/wiki/MIT_License)
//
//	Permission is hereby granted, free of charge, to any person obtaining a copy
//	of this software and associated documentation files (the "Software"), to deal
//	in the Software without restriction, including without limitation the rights 
//	to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
//	of the Software, and to permit persons to whom the Software is furnished to do so, 
//	subject to the following conditions:
//
//	The above copyright notice and this permission notice shall be included in all 
//	copies or substantial portions of the Software.
//
//	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 
//	INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
//	PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 
//	FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
//	ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Ordinaire.Security
{
    /// <summary>
    /// Used for other authorisation mechanism.
    /// </summary>
    public interface IAuthorisation
    {
        /// <summary>
        /// Gets the admin role.
        /// </summary>
        Role AdminRole { get; }

        /// <summary>
        /// Assigns a role to a specified username along with the user who assigns this.
        /// </summary>
        /// <param name="username">designated username with the new role</param>
        /// <param name="role">the role</param>
        /// <param name="who">who assigns this</param>
        /// <returns>true if assignment is successful, else false</returns>
        bool AssignRole(string username, Role role, User who);

        /// <summary>
        /// Creates new role with specified name.
        /// </summary>
        /// <param name="name">role name</param>
        /// <param name="who">user who creates</param>
        /// <param name="parent">parent role</param>
        /// <returns>new instance of Ordinaire.Security.Role</returns>
        Role CreateRole(string name, User who, Role parent = null);

        /// <summary>
        /// Creates new role with specified name.
        /// </summary>
        /// <param name="name">role name</param>
        /// <param name="who">userid who creates</param>
        /// <param name="parent">parent role</param>
        /// <returns>new instance of Ordinaire.Security.Role</returns>
        Role CreateRole(string name, string creatorId, Role parent = null);

        /// <summary>
        /// Returns role with the specified role name.
        /// </summary>
        /// <param name="name">role name</param>
        /// <param name="parent">parent role</param>
        /// <returns>new instance of Ordinaire.Security.Role</returns>
        Role GetRoleByName(string name, Role parent = null);

        /// <summary>
        /// Returns role with the specifid id.
        /// </summary>
        /// <param name="id">role id</param>
        /// <returns>Ordinaire.Security.Role instance</returns>
        Role GetRoleById(int id);

        /// <summary>
        /// Returns all roles assigned to the specified username.
        /// </summary>
        /// <param name="username">the username</param>
        /// <returns>list of roles assigned to specified username</returns>
        List<Role> GetRoles(string username);

        /// <summary>
        /// Clear and creates list of fresh role(s).
        /// </summary>
        /// <param name="names">list of new role names</param>
        /// <param name="creatorId">userid who initiates</param>
        /// <returns>list of created roles</returns>
        List<Role> Setup(string[] names, string creatorId);
    }
}
